package Day05;

import java.util.Scanner;
import org.junit.Test;

public class StudentManage {
	public static class Student {
		private int ID;
		private String name;
		private int  age;
		private String class_Name;
	
	
		public Student(int ID, String name, int age, String class_Name) {
		//	super();
			this.ID = ID;
			this.name = name;
			this.age = age;
			this.class_Name = class_Name;
		}


		public int getID() {
			return ID;
		}


		public void setID(int iD) {
			ID = iD;
		}


		public String getName() {
			return name;
		}


		public void setName(String name) {
			this.name = name;
		}


		public int getAge() {
			return age;
		}


		public void setAge(int age) {
			this.age = age;
		}


		public String getClass_Name() {
			return class_Name;
		}


		public void setClass_Name(String class_Name) {
			this.class_Name = class_Name;
		}

		

	@Override
		public String toString() {
			return "Student [ID=" + ID + ", name=" + name + ", age=" + age + ", class_Name=" + class_Name + "]";
		}

		}
	
	public static void inputInformation(Student[] students){
		Scanner input = new Scanner(System.in);
		for (int i = 0; i < students.length; i++) {
			System.out.println("请输入学生id：");
			int ID  = input.nextInt();
			System.out.println("请输入学生姓名：");
			String  name = input.next();
			System.out.println("请输入学生年龄：");
			int age = input.nextInt();
			System.out.println("请输入学生班级：");
			String class_Name = input.next();
			Student std = new Student(ID, name, age, class_Name);
			students[i] = std;
		}
	}
	public static void showAllInformation(Student[] students) {
		System.out.println("学生信息总览");
		for (int i = 0; i < students.length; i++) {
			System.out.println(students[i]);
		}
	}
	public static void searchByOption(Student[] students) {
		Scanner input = new Scanner(System.in);
		while(true){
			System.out.println();
			System.out.println("请选择查询方法：");
			System.out.println("1.按照ID查找");
			System.out.println("2.按照姓名查找");
			System.out.println("3.按照班级查找");
			System.out.println("4.按照年龄查找");
			System.out.println("0.退出");
			System.out.println();
		
		int choose = input.nextInt();
		if (choose == 0) {
			return;
		}else {
			//choose.eq
		}
		boolean isfind = false;
		switch (choose) {
		case 1:
			while(true){
				System.out.println("请输入需要查询的ID：");
				System.out.println("输入0可返回上一层。");
				int find_id = input.nextInt();
				for (int i = 0; i < students.length; i++) {
					if (find_id == students[i].getID()) {
						System.out.println(students[i].toString());
						System.out.println("输入0可返回上一层。");
						System.out.println();
						isfind = true;
					}
				}
				if (isfind == false) {
					System.out.println("未查询到信息！");
					System.out.println("输入0可返回上一层。");
				}
				if (find_id == 0) {
					break;
				}
			}
			break;
		case 2:
			while(true){
			System.out.println("请输入需要查询的姓名：");
			System.out.println("输入0可返回上一层。");
			String find_name = input.next();
			for (int i = 0; i < students.length; i++) {
				if (find_name.equals(students[i].getName()) ) {
					System.out.println(students[i].toString());
					System.out.println("输入0可返回上一层。");
					System.out.println();
					isfind = true;
				}
			}
			if (isfind == false) {
				System.out.println("未查询到信息！");
				System.out.println("输入0可返回上一层。");
			}
			if (find_name.equals("0")) {
				break;
			}
			}
			break;
		case 3:
			while(true){
			System.out.println("请输入需要查询的班级：");
			System.out.println("输入0可返回上一层。");
			String find_class = input.next();
			for (int i = 0; i < students.length; i++) {
				if (find_class.equals(students[i].getClass_Name())) {
					System.out.println(students[i].toString());
					System.out.println("输入0可返回上一层。");
					System.out.println();
					isfind = true;
				}
			}
			if (isfind == false) {
				System.out.println("未查询到信息！");
				System.out.println("输入0可返回上一层。");
			}
			if (find_class.equals("0")) {
				break;
			}
			}
			break;
		case 4:
			while(true){
			System.out.println("请输入需要查询的年龄：");
			System.out.println("输入0可返回上一层。");
			int find_age = input.nextInt();
			for (int i = 0; i < students.length; i++) {
				if (find_age == students[i].getAge()) {
					System.out.println(students[i].toString());
					System.out.println("输入0可返回上一层。");
					System.out.println();
					isfind = true;
				}
			}
			if (isfind == false) {
				System.out.println("未查询到信息！");
				System.out.println("输入0可返回上一层。");
			}
			if (find_age == 0) {
				break;
			}
			}
			break;
		default:
			break;
			}
		}
	}
	
	@Test
	public void ManageTest(){
		System.out.println("请输入学生数量：");
		Scanner input = new Scanner(System.in);
		int student_Num = input.nextInt();
		Student[] students = new Student[student_Num];
		
		inputInformation(students);//调用信息输入方法
		showAllInformation(students);//调用全部信息展示方法
		searchByOption(students);//调用查询方法
		
	}

}
